<?php

namespace app\common\model\xiservice;

use think\Model;
use app\common\model\xiservice\Area;

class Address extends Model
{

    

    

    // 表名
    protected $name = 'xiservice_address';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
		'province_text',
		'city_text',
		'area_text'
    ];
    
	
    public function getProvinceTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['province_id']) ? $data['province_id'] : 0);
        $province = Area::where('id',$value)->find();
        return $province ? $province['name'] : '';
    }
    
    public function getCityTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['city_id']) ? $data['city_id'] : 0);
        $city = Area::where('id',$value)->find();
        return $city ? $city['name'] : '';
    }
	
    public function getAreaTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['area_id']) ? $data['area_id'] : 0);
        $area = Area::where('id',$value)->find();
        return $area ? $area['name'] : '';
    }	






}
